#include "digitalclock.h"
#include <QLCDNumber>
#include <QTimer>
#include <QTime>
#include <QDate>
#include <QDebug>
#include <QLabel>
#include <QFont>

DigitalClock::DigitalClock(QWidget *parent)
    : QLCDNumber(parent)
{
    setSegmentStyle(QLCDNumber::Filled);

    label->setParent(this);
    label->setFont(QFont("楷体",15));

    showTime();

    auto *timer = new QTimer(this);
    connect(timer,&QTimer::timeout,this, &DigitalClock::showTime);
    timer->start(1000);

    setWindowTitle("Digital Clock");
    resize(375, 180);
    setMode(QLCDNumber::Hex);

 }

void DigitalClock::showTime()
{
     QTime time = QTime::currentTime();
     QDate date = QDate::currentDate();
     QString text = date.toString("yyyy-MM-dd  dddd  ") + time.toString("hh:mm:ss");

     label->setText(text);

     display(text);
}
